
<!DOCTYPE html>

<html lang="zh">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>第二回：艺术画笔见乾坤 &#8212; fantastic-matplotlib</title>
    
  <link href="../_static/css/theme.css" rel="stylesheet" />
  <link href="../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />

    
  <link rel="stylesheet"
    href="../_static/vendor/fontawesome/5.13.0/css/all.min.css">
  <link rel="preload" as="font" type="font/woff2" crossorigin
    href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
  <link rel="preload" as="font" type="font/woff2" crossorigin
    href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">

    
      

    
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../_static/togglebutton.css" />
    <link rel="stylesheet" type="text/css" href="../_static/mystnb.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    
  <link rel="preload" as="script" href="../_static/js/index.1c5a1a01449ed65a7b51.js">

    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/togglebutton.js"></script>
    <script >var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
    <script src="../_static/sphinx-book-theme.12a9622fbb08dcb3a2a40b2c02b83a57.js"></script>
    <link rel="shortcut icon" href="../_static/logo.png"/>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="第三回：布局格式定方圆" href="../%E7%AC%AC%E4%B8%89%E5%9B%9E%EF%BC%9A%E5%B8%83%E5%B1%80%E6%A0%BC%E5%BC%8F%E5%AE%9A%E6%96%B9%E5%9C%86/index.html" />
    <link rel="prev" title="第一回：Matplotlib初相识" href="../%E7%AC%AC%E4%B8%80%E5%9B%9E%EF%BC%9AMatplotlib%E5%88%9D%E7%9B%B8%E8%AF%86/index.html" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="docsearch:language" content="en" />
    
  </head>
  <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
    
    <div class="container-fluid" id="banner"></div>

    

    <div class="container-xl">
      <div class="row">
          
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
    
        <div class="navbar-brand-box">
    <a class="navbar-brand text-wrap" href="../index.html">
      
      <img src="../_static/logo.png" class="logo" alt="logo">
      
      
      <h1 class="site-logo" id="site-title">fantastic-matplotlib</h1>
      
    </a>
</div><form class="bd-search d-flex align-items-center" action="../search.html" method="get">
  <i class="icon fas fa-search"></i>
  <input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
    <div class="bd-toc-item active">
        <ul class="current nav bd-sidenav">
 <li class="toctree-l1">
  <a class="reference internal" href="../%E7%AC%AC%E4%B8%80%E5%9B%9E%EF%BC%9AMatplotlib%E5%88%9D%E7%9B%B8%E8%AF%86/index.html">
   第一回：Matplotlib初相识
  </a>
 </li>
 <li class="toctree-l1 current active">
  <a class="current reference internal" href="#">
   第二回：艺术画笔见乾坤
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="../%E7%AC%AC%E4%B8%89%E5%9B%9E%EF%BC%9A%E5%B8%83%E5%B1%80%E6%A0%BC%E5%BC%8F%E5%AE%9A%E6%96%B9%E5%9C%86/index.html">
   第三回：布局格式定方圆
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="../%E7%AC%AC%E5%9B%9B%E5%9B%9E%EF%BC%9A%E6%96%87%E5%AD%97%E5%9B%BE%E4%BE%8B%E5%B0%BD%E7%9C%89%E7%9B%AE/index.html">
   第四回：文字图例尽眉目
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="../%E7%AC%AC%E4%BA%94%E5%9B%9E%EF%BC%9A%E6%A0%B7%E5%BC%8F%E8%89%B2%E5%BD%A9%E7%A7%80%E8%8A%B3%E5%8D%8E/index.html">
   第五回：样式色彩秀芳华
  </a>
 </li>
</ul>

    </div>
</nav> <!-- To handle the deprecated key -->

<div class="navbar_extra_footer">
  Theme by the <a href="https://ebp.jupyterbook.org">Executable Book Project</a>
</div>

</div>


          


          
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
    
    <div class="topbar container-xl fixed-top">
    <div class="topbar-contents row">
        <div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
        <div class="col pl-md-4 topbar-main">
            
            <button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
                data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
                aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
                title="Toggle navigation" data-toggle="tooltip" data-placement="left">
                <i class="fas fa-bars"></i>
                <i class="fas fa-arrow-left"></i>
                <i class="fas fa-arrow-up"></i>
            </button>
            
            
<div class="dropdown-buttons-trigger">
    <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
            class="fas fa-download"></i></button>

    <div class="dropdown-buttons">
        <!-- ipynb file if we had a myst markdown file -->
        
        <!-- Download raw file -->
        <a class="dropdown-buttons" href="../_sources/第二回：艺术画笔见乾坤/index.md.txt"><button type="button"
                class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
                data-placement="left">.md</button></a>
        <!-- Download PDF via print -->
        <button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
            onClick="window.print()" data-toggle="tooltip" data-placement="left">.pdf</button>
    </div>
</div>

            <!-- Source interaction buttons -->

<div class="dropdown-buttons-trigger">
    <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
        aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
    <div class="dropdown-buttons sourcebuttons">
        <a class="repository-button"
            href="https://github.com/datawhalechina/fantastic-matplotlib"><button type="button" class="btn btn-secondary topbarbtn"
                data-toggle="tooltip" data-placement="left" title="Source repository"><i
                    class="fab fa-github"></i>repository</button></a>
        <a class="issues-button"
            href="https://github.com/datawhalechina/fantastic-matplotlib/issues/new?title=Issue%20on%20page%20%2F第二回：艺术画笔见乾坤/index.html&body=Your%20issue%20content%20here."><button
                type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
                title="Open an issue"><i class="fas fa-lightbulb"></i>open issue</button></a>
        <a class="edit-button" href="https://github.com/datawhalechina/fantastic-matplotlib/edit/master/第二回：艺术画笔见乾坤/index.md"><button
                type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
                title="Edit this page"><i class="fas fa-pencil-alt"></i>suggest edit</button></a>
    </div>
</div>

            <!-- Full screen (wrap in <a> to have style consistency -->

<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
        data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
        title="Fullscreen mode"><i
            class="fas fa-expand"></i></button></a>

            <!-- Launch buttons -->

        </div>

        <!-- Table of contents -->
        <div class="d-none d-md-block col-md-2 bd-toc show">
            
            <div class="tocsection onthispage pt-5 pb-3">
                <i class="fas fa-list"></i> Contents
            </div>
            <nav id="bd-toc-nav">
                <ul class="visible nav section-nav flex-column">
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#id2">
   一、概述
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#matplotlibapi">
     1. matplotlib的三层api
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#artist">
     2. Artist的分类
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#primitives">
   二、基本元素 - primitives
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#dlines">
     1. 2DLines
    </a>
    <ul class="nav section-nav flex-column">
     <li class="toc-h4 nav-item toc-entry">
      <a class="reference internal nav-link" href="#a-line2d">
       a. 如何设置Line2D的属性
      </a>
     </li>
     <li class="toc-h4 nav-item toc-entry">
      <a class="reference internal nav-link" href="#b-lines">
       b. 如何绘制lines
      </a>
     </li>
    </ul>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#patches">
     2. patches
    </a>
    <ul class="nav section-nav flex-column">
     <li class="toc-h4 nav-item toc-entry">
      <a class="reference internal nav-link" href="#a-rectangle">
       a. Rectangle-矩形
      </a>
     </li>
     <li class="toc-h4 nav-item toc-entry">
      <a class="reference internal nav-link" href="#b-polygon">
       b. Polygon-多边形
      </a>
     </li>
     <li class="toc-h4 nav-item toc-entry">
      <a class="reference internal nav-link" href="#c-wedge">
       c. Wedge-契形
      </a>
     </li>
    </ul>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#collections">
     3. collections
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#images">
     4. images
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#object-container">
   三、对象容器 - Object container
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#figure">
     1. Figure容器
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#axes">
     2. Axes容器
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#axis">
     3. Axis容器
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#tick">
     4. Tick容器
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#id3">
   思考题
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#id4">
   参考资料
  </a>
 </li>
</ul>

            </nav>
        </div>
    </div>
</div>
    <div id="main-content" class="row">
        <div class="col-12 col-md-9 pl-md-3 pr-md-0">
        
              <div>
                
  <div class="section" id="id1">
<h1>第二回：艺术画笔见乾坤<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h1>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">matplotlib</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib.lines</span> <span class="kn">import</span> <span class="n">Line2D</span>   
<span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <span class="n">Circle</span><span class="p">,</span> <span class="n">Wedge</span>
<span class="kn">from</span> <span class="nn">matplotlib.collections</span> <span class="kn">import</span> <span class="n">PatchCollection</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="id2">
<h2>一、概述<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h2>
<div class="section" id="matplotlibapi">
<h3>1. matplotlib的三层api<a class="headerlink" href="#matplotlibapi" title="永久链接至标题">¶</a></h3>
<p>matplotlib的原理或者说基础逻辑是，用Artist对象在画布(canvas)上绘制(Render)图形。<br />
就和人作画的步骤类似：</p>
<ol class="simple">
<li><p>准备一块画布或画纸</p></li>
<li><p>准备好颜料、画笔等制图工具</p></li>
<li><p>作画</p></li>
</ol>
<p>所以matplotlib有三个层次的API：</p>
<p><code class="docutils literal notranslate"><span class="pre">matplotlib.backend_bases.FigureCanvas</span></code> 代表了绘图区，所有的图像都是在绘图区完成的<br />
<code class="docutils literal notranslate"><span class="pre">matplotlib.backend_bases.Renderer</span></code> 代表了渲染器，可以近似理解为画笔，控制如何在 FigureCanvas 上画图。<br />
<code class="docutils literal notranslate"><span class="pre">matplotlib.artist.Artist</span></code> 代表了具体的图表组件，即调用了Renderer的接口在Canvas上作图。<br />
前两者处理程序和计算机的底层交互的事项，第三项Artist就是具体的调用接口来做出我们想要的图，比如图形、文本、线条的设定。所以通常来说，我们95%的时间，都是用来和matplotlib.artist.Artist类打交道的。</p>
</div>
<div class="section" id="artist">
<h3>2. Artist的分类<a class="headerlink" href="#artist" title="永久链接至标题">¶</a></h3>
<p>Artist有两种类型：<code class="docutils literal notranslate"><span class="pre">primitives</span></code> 和<code class="docutils literal notranslate"><span class="pre">containers</span></code>。</p>
<p><code class="docutils literal notranslate"><span class="pre">primitive</span></code>是基本要素，它包含一些我们要在绘图区作图用到的标准图形对象，如<strong>曲线Line2D，文字text，矩形Rectangle，图像image</strong>等。</p>
<p><code class="docutils literal notranslate"><span class="pre">container</span></code>是容器，即用来装基本要素的地方，包括<strong>图形figure、坐标系Axes和坐标轴Axis</strong>。他们之间的关系如下图所示：<br />
<img alt="分类" src="https://img-blog.csdnimg.cn/20201122230916134.jpeg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zODYwNDk2MQ==,size_16,color_FFFFFF,t_70#pic_center" /></p>
<p>可视化中常见的artist类可以参考下图这张表格，解释下每一列的含义。<br />
第一列表示matplotlib中子图上的辅助方法，可以理解为可视化中不同种类的图表类型，如柱状图，折线图，直方图等，这些图表都可以用这些辅助方法直接画出来，属于更高层级的抽象。</p>
<p>第二列表示不同图表背后的artist类，比如折线图方法<code class="docutils literal notranslate"><span class="pre">plot</span></code>在底层用到的就是<code class="docutils literal notranslate"><span class="pre">Line2D</span></code>这一artist类。</p>
<p>第三列是第二列的列表容器，例如所有在子图中创建的<code class="docutils literal notranslate"><span class="pre">Line2D</span></code>对象都会被自动收集到<code class="docutils literal notranslate"><span class="pre">ax.lines</span></code>返回的列表中。</p>
<p>下一节的具体案例更清楚地阐释了这三者的关系，其实在很多时候，我们只用记住第一列的辅助方法进行绘图即可，而无需关注具体底层使用了哪些类，但是了解底层类有助于我们绘制一些复杂的图表，因此也很有必要了解。</p>
<table class="colwidths-auto table">
<thead>
<tr class="row-odd"><th class="head"><p>Axes helper method</p></th>
<th class="head"><p>Artist</p></th>
<th class="head"><p>Container</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">bar</span></code> - bar charts</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Rectangle</span></code></p></td>
<td><p>ax.patches</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">errorbar</span></code> - error bar plots</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Line2D</span></code> and <code class="docutils literal notranslate"><span class="pre">Rectangle</span></code></p></td>
<td><p>ax.lines and ax.patches</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">fill</span></code> - shared area</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Polygon</span></code></p></td>
<td><p>ax.patches</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">hist</span></code> - histograms</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Rectangle</span></code></p></td>
<td><p>ax.patches</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imshow</span></code> - image data</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">AxesImage</span></code></p></td>
<td><p>ax.images</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">plot</span></code> - xy plots</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Line2D</span></code></p></td>
<td><p>ax.lines</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">scatter</span></code> - scatter charts</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PolyCollection</span></code></p></td>
<td><p>ax.collections</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="primitives">
<h2>二、基本元素 - primitives<a class="headerlink" href="#primitives" title="永久链接至标题">¶</a></h2>
<p>各容器中可能会包含多种<code class="docutils literal notranslate"><span class="pre">基本要素-primitives</span></code>, 所以先介绍下primitives，再介绍容器。</p>
<p>本章重点介绍下 <code class="docutils literal notranslate"><span class="pre">primitives</span></code> 的几种类型：<strong>曲线-Line2D，矩形-Rectangle，多边形-Polygon，图像-image</strong></p>
<div class="section" id="dlines">
<h3>1. 2DLines<a class="headerlink" href="#dlines" title="永久链接至标题">¶</a></h3>
<p>在matplotlib中曲线的绘制，主要是通过类 <code class="docutils literal notranslate"><span class="pre">matplotlib.lines.Line2D</span></code> 来完成的。</p>
<p>matplotlib中<code class="docutils literal notranslate"><span class="pre">线-line</span></code>的含义：它表示的可以是连接所有顶点的实线样式，也可以是每个顶点的标记。此外，这条线也会受到绘画风格的影响，比如，我们可以创建虚线种类的线。</p>
<p>它的构造函数：</p>
<blockquote>
<div><p>class matplotlib.lines.Line2D(xdata, ydata, linewidth=None, linestyle=None, color=None, marker=None, markersize=None, markeredgewidth=None, markeredgecolor=None, markerfacecolor=None, markerfacecoloralt='none', fillstyle=None, antialiased=None, dash_capstyle=None, solid_capstyle=None, dash_joinstyle=None, solid_joinstyle=None, pickradius=5, drawstyle=None, markevery=None, **kwargs)</p>
</div></blockquote>
<p>其中常用的的参数有：</p>
<ul class="simple">
<li><p><strong>xdata</strong>:需要绘制的line中点的在x轴上的取值，若忽略，则默认为range(1,len(ydata)+1)</p></li>
<li><p><strong>ydata</strong>:需要绘制的line中点的在y轴上的取值</p></li>
<li><p><strong>linewidth</strong>:线条的宽度</p></li>
<li><p><strong>linestyle</strong>:线型</p></li>
<li><p><strong>color</strong>:线条的颜色</p></li>
<li><p><strong>marker</strong>:点的标记，详细可参考<a class="reference external" href="https://matplotlib.org/api/markers_api.html#module-matplotlib.markers">markers API</a></p></li>
<li><p><strong>markersize</strong>:标记的size</p></li>
</ul>
<p>其他详细参数可参考<a class="reference external" href="https://matplotlib.org/stable/api/_as_gen/matplotlib.lines.Line2D.html">Line2D官方文档</a></p>
<div class="section" id="a-line2d">
<h4>a. 如何设置Line2D的属性<a class="headerlink" href="#a-line2d" title="永久链接至标题">¶</a></h4>
<p>有三种方法可以用设置线的属性。</p>
<ol class="simple">
<li><p>直接在plot()函数中设置</p></li>
<li><p>通过获得线对象，对线对象进行设置</p></li>
<li><p>获得线属性，使用setp()函数设置</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 1) 直接在plot()函数中设置</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">10</span><span class="p">);</span> <span class="c1"># 设置线的粗细参数为10</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_3_01.png" src="../_images/index_3_01.png" />
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 2) 通过获得线对象，对线对象进行设置</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span> <span class="c1"># 这里等号坐标的line,是一个列表解包的操作，目的是获取plt.plot返回列表中的Line2D对象</span>
<span class="n">line</span><span class="o">.</span><span class="n">set_antialiased</span><span class="p">(</span><span class="kc">False</span><span class="p">);</span> <span class="c1"># 关闭抗锯齿功能</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_4_01.png" src="../_images/index_4_01.png" />
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 3) 获得线属性，使用setp()函数设置</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">lines</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">10</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_5_01.png" src="../_images/index_5_01.png" />
</div>
</div>
</div>
<div class="section" id="b-lines">
<h4>b. 如何绘制lines<a class="headerlink" href="#b-lines" title="永久链接至标题">¶</a></h4>
<ol class="simple">
<li><p>绘制直线line</p></li>
<li><p>errorbar绘制误差折线图</p></li>
</ol>
<p>介绍两种绘制直线line常用的方法:</p>
<ul class="simple">
<li><p><strong>plot方法绘制</strong></p></li>
<li><p><strong>Line2D对象绘制</strong></p></li>
</ul>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 1. plot方法绘制</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y1</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">y2</span><span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">11</span><span class="p">]</span>

<span class="n">fig</span><span class="p">,</span><span class="n">ax</span><span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y1</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y2</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">lines</span><span class="p">);</span> <span class="c1"># 通过直接使用辅助方法画线，打印ax.lines后可以看到在matplotlib在底层创建了两个Line2D对象</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[&lt;matplotlib.lines.Line2D object at 0x0000020C25E80940&gt;, &lt;matplotlib.lines.Line2D object at 0x0000020C25E80CD0&gt;]
</pre></div>
</div>
<img alt="../_images/index_7_1.png" src="../_images/index_7_1.png" />
</div>
</div>
<p>​</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 2. Line2D对象绘制</span>

<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y1</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">y2</span><span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">11</span><span class="p">]</span>
<span class="n">fig</span><span class="p">,</span><span class="n">ax</span><span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">Line2D</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y1</span><span class="p">),</span> <span class="n">Line2D</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;orange&#39;</span><span class="p">)]</span>  <span class="c1"># 显式创建Line2D对象</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="c1"># 使用add_line方法将创建的Line2D添加到子图中</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">11</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_9_01.png" src="../_images/index_9_01.png" />
</div>
</div>
<p>​<br />
​</p>
<p><strong>2) errorbar绘制误差折线图</strong><br />
pyplot里有个专门绘制误差线的功能，通过<code class="docutils literal notranslate"><span class="pre">errorbar</span></code>类实现，它的构造函数：</p>
<blockquote>
<div><p>matplotlib.pyplot.errorbar(x, y, yerr=None, xerr=None, fmt='', ecolor=None, elinewidth=None, capsize=None, barsabove=False, lolims=False, uplims=False, xlolims=False, xuplims=False, errorevery=1, capthick=None, *, data=None, **kwargs)</p>
</div></blockquote>
<p>其中最主要的参数是前几个:</p>
<ul class="simple">
<li><p><strong>x</strong>：需要绘制的line中点的在x轴上的取值</p></li>
<li><p><strong>y</strong>：需要绘制的line中点的在y轴上的取值</p></li>
<li><p><strong>yerr</strong>：指定y轴水平的误差</p></li>
<li><p><strong>xerr</strong>：指定x轴水平的误差</p></li>
<li><p><strong>fmt</strong>：指定折线图中某个点的颜色，形状，线条风格，例如‘co--’</p></li>
<li><p><strong>ecolor</strong>：指定error bar的颜色</p></li>
<li><p><strong>elinewidth</strong>：指定error bar的线条宽度</p></li>
</ul>
<p>绘制errorbar</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="mf">2.5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span> <span class="o">/</span> <span class="mi">20</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span>
<span class="n">yerr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">errorbar</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="o">+</span><span class="mi">3</span><span class="p">,</span><span class="n">yerr</span><span class="o">=</span><span class="n">yerr</span><span class="p">,</span><span class="n">fmt</span><span class="o">=</span><span class="s1">&#39;o-&#39;</span><span class="p">,</span><span class="n">ecolor</span><span class="o">=</span><span class="s1">&#39;r&#39;</span><span class="p">,</span><span class="n">elinewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_11_01.png" src="../_images/index_11_01.png" />
</div>
</div>
<p>​<br />
​</p>
</div>
</div>
<div class="section" id="patches">
<h3>2. patches<a class="headerlink" href="#patches" title="永久链接至标题">¶</a></h3>
<p>matplotlib.patches.Patch类是二维图形类，并且它是众多二维图形的父类，它的所有子类见<a class="reference external" href="https://matplotlib.org/stable/api/patches_api.html">matplotlib.patches API</a>  ，<br />
Patch类的构造函数：</p>
<blockquote>
<div><p>Patch(edgecolor=None, facecolor=None, color=None,
linewidth=None, linestyle=None, antialiased=None,
hatch=None, fill=True, capstyle=None, joinstyle=None,
**kwargs)</p>
</div></blockquote>
<p>本小节重点讲述三种最常见的子类，矩形，多边形和楔形。</p>
<div class="section" id="a-rectangle">
<h4>a. Rectangle-矩形<a class="headerlink" href="#a-rectangle" title="永久链接至标题">¶</a></h4>
<p><code class="docutils literal notranslate"><span class="pre">Rectangle</span></code>矩形类在官网中的定义是： 通过锚点xy及其宽度和高度生成。
Rectangle本身的主要比较简单，即xy控制锚点，width和height分别控制宽和高。它的构造函数：</p>
<blockquote>
<div><p>class matplotlib.patches.Rectangle(xy, width, height, angle=0.0, **kwargs)</p>
</div></blockquote>
<p>在实际中最常见的矩形图是<code class="docutils literal notranslate"><span class="pre">hist直方图</span></code>和<code class="docutils literal notranslate"><span class="pre">bar条形图</span></code>。</p>
<p><strong>1) hist-直方图</strong></p>
<blockquote>
<div><p>matplotlib.pyplot.hist(x,bins=None,range=None, density=None, bottom=None, histtype='bar', align='mid', log=False, color=None, label=None, stacked=False, normed=None)</p>
</div></blockquote>
<p>下面是一些常用的参数：</p>
<ul class="simple">
<li><p><strong>x</strong>: 数据集，最终的直方图将对数据集进行统计</p></li>
<li><p><strong>bins</strong>: 统计的区间分布</p></li>
<li><p><strong>range</strong>: tuple, 显示的区间，range在没有给出bins时生效</p></li>
<li><p><strong>density</strong>: bool，默认为false，显示的是频数统计结果，为True则显示频率统计结果，这里需要注意，频率统计结果=区间数目/(总数*区间宽度)，和normed效果一致，官方推荐使用density</p></li>
<li><p><strong>histtype</strong>: 可选{'bar', 'barstacked', 'step', 'stepfilled'}之一，默认为bar，推荐使用默认配置，step使用的是梯状，stepfilled则会对梯状内部进行填充，效果与bar类似</p></li>
<li><p><strong>align</strong>: 可选{'left', 'mid', 'right'}之一，默认为'mid'，控制柱状图的水平分布，left或者right，会有部分空白区域，推荐使用默认</p></li>
<li><p><strong>log</strong>: bool，默认False,即y坐标轴是否选择指数刻度</p></li>
<li><p><strong>stacked</strong>: bool，默认为False，是否为堆积状图</p></li>
</ul>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># hist绘制直方图</span>
<span class="n">x</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">100</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span> <span class="c1">#生成[0-100)之间的100个数据,即 数据集 </span>
<span class="n">bins</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">101</span><span class="p">,</span><span class="mi">10</span><span class="p">)</span> <span class="c1">#设置连续的边界值，即直方图的分布区间[0,10),[10,20)... </span>
<span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">bins</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;fuchsia&#39;</span><span class="p">,</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span><span class="c1">#alpha设置透明度，0为完全透明 </span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;scores&#39;</span><span class="p">)</span> 
<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;count&#39;</span><span class="p">)</span> 
<span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">100</span><span class="p">);</span> <span class="c1">#设置x轴分布范围 plt.show()</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_13_01.png" src="../_images/index_13_01.png" />
</div>
</div>
<p>​</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Rectangle矩形类绘制直方图</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">])</span>
<span class="n">df</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span><span class="s1">&#39;data&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span>
<span class="n">df</span><span class="p">[</span><span class="s1">&#39;fenzu&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">cut</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">],</span> <span class="n">bins</span><span class="o">=</span><span class="n">bins</span><span class="p">,</span> <span class="n">right</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span><span class="n">include_lowest</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="n">df_cnt</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">&#39;fenzu&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value_counts</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
<span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span><span class="s1">&#39;mini&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_cnt</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span><span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s1">&#39;\[(.*)\,&#39;</span><span class="p">,</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span><span class="s1">&#39;maxi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_cnt</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span><span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s1">&#39;\,(.*)\)&#39;</span><span class="p">,</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span><span class="s1">&#39;width&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_cnt</span><span class="p">[</span><span class="s1">&#39;maxi&#39;</span><span class="p">]</span><span class="o">-</span> <span class="n">df_cnt</span><span class="p">[</span><span class="s1">&#39;mini&#39;</span><span class="p">]</span>
<span class="n">df_cnt</span><span class="o">.</span><span class="n">sort_values</span><span class="p">(</span><span class="s1">&#39;mini&#39;</span><span class="p">,</span><span class="n">ascending</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span><span class="n">inplace</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span>
<span class="n">df_cnt</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">inplace</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span><span class="n">drop</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span>

<span class="c1">#用Rectangle把hist绘制出来</span>

<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">df_cnt</span><span class="o">.</span><span class="n">index</span><span class="p">:</span>
    <span class="n">rect</span> <span class="o">=</span>  <span class="n">plt</span><span class="o">.</span><span class="n">Rectangle</span><span class="p">((</span><span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="s1">&#39;mini&#39;</span><span class="p">],</span><span class="mi">0</span><span class="p">),</span><span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="s1">&#39;width&#39;</span><span class="p">],</span><span class="n">df_cnt</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="s1">&#39;fenzu&#39;</span><span class="p">])</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">rect</span><span class="p">)</span>

<span class="n">ax1</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">16</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_15_01.png" src="../_images/index_15_01.png" />
</div>
</div>
<p>​</p>
<p>​</p>
<p><strong>2) bar-柱状图</strong></p>
<blockquote>
<div><p>matplotlib.pyplot.bar(left, height, alpha=1, width=0.8, color=, edgecolor=, label=, lw=3)</p>
</div></blockquote>
<p>下面是一些常用的参数：</p>
<ul class="simple">
<li><p><strong>left</strong>：x轴的位置序列，一般采用range函数产生一个序列，但是有时候可以是字符串</p></li>
<li><p><strong>height</strong>：y轴的数值序列，也就是柱形图的高度，一般就是我们需要展示的数据；</p></li>
<li><p><strong>alpha</strong>：透明度，值越小越透明</p></li>
<li><p><strong>width</strong>：为柱形图的宽度，一般这是为0.8即可；</p></li>
<li><p><strong>color或facecolor</strong>：柱形图填充的颜色；</p></li>
<li><p><strong>edgecolor</strong>：图形边缘颜色</p></li>
<li><p><strong>label</strong>：解释每个图像代表的含义，这个参数是为legend()函数做铺垫的，表示该次bar的标签</p></li>
</ul>
<p>有两种方式绘制柱状图</p>
<ul class="simple">
<li><p>bar绘制柱状图</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Rectangle</span></code>矩形类绘制柱状图</p></li>
</ul>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># bar绘制柱状图</span>
<span class="n">y</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">16</span><span class="p">),</span> <span class="n">y</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;yellow&#39;</span><span class="p">,</span> <span class="n">edgecolor</span><span class="o">=</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;The First Bar&#39;</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">3</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_17_01.png" src="../_images/index_17_01.png" />
</div>
</div>
<p>​</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Rectangle矩形类绘制柱状图</span>
<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="p">):</span>
    <span class="n">rect</span> <span class="o">=</span>  <span class="n">plt</span><span class="o">.</span><span class="n">Rectangle</span><span class="p">((</span><span class="n">i</span><span class="o">+</span><span class="mf">0.25</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span><span class="mf">0.5</span><span class="p">,</span><span class="n">i</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">rect</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">16</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_19_0.png" src="../_images/index_19_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
</div>
<div class="section" id="b-polygon">
<h4>b. Polygon-多边形<a class="headerlink" href="#b-polygon" title="永久链接至标题">¶</a></h4>
<p>matplotlib.patches.Polygon类是多边形类。它的构造函数：</p>
<blockquote>
<div><p>class matplotlib.patches.Polygon(xy, closed=True, **kwargs)</p>
</div></blockquote>
<p>xy是一个N×2的numpy array，为多边形的顶点。<br />
closed为True则指定多边形将起点和终点重合从而显式关闭多边形。</p>
<p>matplotlib.patches.Polygon类中常用的是fill类，它是基于xy绘制一个填充的多边形，它的定义：</p>
<blockquote>
<div><p>matplotlib.pyplot.fill(*args, data=None, **kwargs)</p>
</div></blockquote>
<p>参数说明 : 关于x、y和color的序列，其中color是可选的参数，每个多边形都是由其节点的x和y位置列表定义的，后面可以选择一个颜色说明符。您可以通过提供多个x、y、[颜色]组来绘制多个多边形。</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 用fill来绘制图形</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span> 
<span class="n">y1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">y2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">x</span><span class="p">)</span> 
<span class="n">plt</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;g&quot;</span><span class="p">,</span> <span class="n">alpha</span> <span class="o">=</span> <span class="mf">0.3</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_21_0.png" src="../_images/index_21_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
</div>
<div class="section" id="c-wedge">
<h4>c. Wedge-契形<a class="headerlink" href="#c-wedge" title="永久链接至标题">¶</a></h4>
<p>matplotlib.patches.Wedge类是楔型类。其基类是matplotlib.patches.Patch，它的构造函数：</p>
<blockquote>
<div><p>class matplotlib.patches.Wedge(center, r, theta1, theta2, width=None, **kwargs)</p>
</div></blockquote>
<p>一个Wedge-楔型 是以坐标x,y为中心，半径为r，从θ1扫到θ2(单位是度)。<br />
如果宽度给定，则从内半径r -宽度到外半径r画出部分楔形。wedge中比较常见的是绘制饼状图。</p>
<p>matplotlib.pyplot.pie语法：</p>
<blockquote>
<div><p>matplotlib.pyplot.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=0, radius=1, counterclock=True, wedgeprops=None, textprops=None, center=0, 0, frame=False, rotatelabels=False, *, normalize=None, data=None)</p>
</div></blockquote>
<p>制作数据x的饼图，每个楔子的面积用x/sum(x)表示。<br />
其中最主要的参数是前4个：</p>
<ul class="simple">
<li><p><strong>x</strong>：楔型的形状，一维数组。</p></li>
<li><p><strong>explode</strong>：如果不是等于None，则是一个len(x)数组，它指定用于偏移每个楔形块的半径的分数。</p></li>
<li><p><strong>labels</strong>：用于指定每个楔型块的标记，取值是列表或为None。</p></li>
<li><p><strong>colors</strong>：饼图循环使用的颜色序列。如果取值为None，将使用当前活动循环中的颜色。</p></li>
<li><p><strong>startangle</strong>：饼状图开始的绘制的角度。</p></li>
</ul>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># pie绘制饼状图</span>
<span class="n">labels</span> <span class="o">=</span> <span class="s1">&#39;Frogs&#39;</span><span class="p">,</span> <span class="s1">&#39;Hogs&#39;</span><span class="p">,</span> <span class="s1">&#39;Dogs&#39;</span><span class="p">,</span> <span class="s1">&#39;Logs&#39;</span>
<span class="n">sizes</span> <span class="o">=</span> <span class="p">[</span><span class="mi">15</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">10</span><span class="p">]</span> 
<span class="n">explode</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> 
<span class="n">fig1</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span> 
<span class="n">ax1</span><span class="o">.</span><span class="n">pie</span><span class="p">(</span><span class="n">sizes</span><span class="p">,</span> <span class="n">explode</span><span class="o">=</span><span class="n">explode</span><span class="p">,</span> <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> <span class="n">autopct</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">%1.1f%%</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">shadow</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">startangle</span><span class="o">=</span><span class="mi">90</span><span class="p">)</span> 
<span class="n">ax1</span><span class="o">.</span><span class="n">axis</span><span class="p">(</span><span class="s1">&#39;equal&#39;</span><span class="p">);</span> <span class="c1"># Equal aspect ratio ensures that pie is drawn as a circle. </span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_23_0.png" src="../_images/index_23_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># wedge绘制饼图</span>
<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">))</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
<span class="n">theta1</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">sizes</span> <span class="o">=</span> <span class="p">[</span><span class="mi">15</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">10</span><span class="p">]</span> 
<span class="n">patches</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">patches</span> <span class="o">+=</span> <span class="p">[</span>
    <span class="n">Wedge</span><span class="p">((</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="mf">.4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">54</span><span class="p">),</span>           
    <span class="n">Wedge</span><span class="p">((</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="mf">.4</span><span class="p">,</span> <span class="mi">54</span><span class="p">,</span> <span class="mi">162</span><span class="p">),</span>  
    <span class="n">Wedge</span><span class="p">((</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="mf">.4</span><span class="p">,</span> <span class="mi">162</span><span class="p">,</span> <span class="mi">324</span><span class="p">),</span>           
    <span class="n">Wedge</span><span class="p">((</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="mf">.4</span><span class="p">,</span> <span class="mi">324</span><span class="p">,</span> <span class="mi">360</span><span class="p">),</span>  
<span class="p">]</span>
<span class="n">colors</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">patches</span><span class="p">))</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">PatchCollection</span><span class="p">(</span><span class="n">patches</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.8</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">add_collection</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_25_0.png" src="../_images/index_25_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
</div>
</div>
<div class="section" id="collections">
<h3>3. collections<a class="headerlink" href="#collections" title="永久链接至标题">¶</a></h3>
<p>collections类是用来绘制一组对象的集合，collections有许多不同的子类，如RegularPolyCollection, CircleCollection, Pathcollection, 分别对应不同的集合子类型。其中比较常用的就是散点图，它是属于PathCollection子类，scatter方法提供了该类的封装，根据x与y绘制不同大小或颜色标记的散点图。 它的构造方法：</p>
<blockquote>
<div><p>Axes.scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=<deprecated parameter>, edgecolors=None, *, plotnonfinite=False, data=None, **kwargs)</p>
</div></blockquote>
<p>其中最主要的参数是前5个：</p>
<ul class="simple">
<li><p><strong>x</strong>：数据点x轴的位置</p></li>
<li><p><strong>y</strong>：数据点y轴的位置</p></li>
<li><p><strong>s</strong>：尺寸大小</p></li>
<li><p><strong>c</strong>：可以是单个颜色格式的字符串，也可以是一系列颜色</p></li>
<li><p><strong>marker</strong>: 标记的类型</p></li>
</ul>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 用scatter绘制散点图</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span> 
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> 
<span class="n">s</span> <span class="o">=</span> <span class="p">[</span><span class="mi">20</span><span class="o">*</span><span class="mi">2</span><span class="o">**</span><span class="n">n</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">))]</span> 
<span class="n">plt</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">s</span><span class="o">=</span><span class="n">s</span><span class="p">)</span> <span class="p">;</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_27_0.png" src="../_images/index_27_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
</div>
<div class="section" id="images">
<h3>4. images<a class="headerlink" href="#images" title="永久链接至标题">¶</a></h3>
<p>images是matplotlib中绘制image图像的类，其中最常用的imshow可以根据数组绘制成图像，它的构造函数：</p>
<blockquote>
<div><p>class matplotlib.image.AxesImage(ax, cmap=None, norm=None, interpolation=None, origin=None, extent=None, filternorm=True, filterrad=4.0, resample=False, **kwargs)</p>
</div></blockquote>
<p>imshow根据数组绘制图像</p>
<blockquote>
<div><p>matplotlib.pyplot.imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=<deprecated parameter>, filternorm=1, filterrad=4.0, imlim=<deprecated parameter>, resample=None, url=None, *, data=None, **kwargs）</p>
</div></blockquote>
<p>使用imshow画图时首先需要传入一个数组，数组对应的是空间内的像素位置和像素点的值，interpolation参数可以设置不同的差值方法，具体效果如下。</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;none&#39;</span><span class="p">,</span> <span class="s1">&#39;nearest&#39;</span><span class="p">,</span> <span class="s1">&#39;bilinear&#39;</span><span class="p">,</span> <span class="s1">&#39;bicubic&#39;</span><span class="p">,</span> <span class="s1">&#39;spline16&#39;</span><span class="p">,</span>
           <span class="s1">&#39;spline36&#39;</span><span class="p">,</span> <span class="s1">&#39;hanning&#39;</span><span class="p">,</span> <span class="s1">&#39;hamming&#39;</span><span class="p">,</span> <span class="s1">&#39;hermite&#39;</span><span class="p">,</span> <span class="s1">&#39;kaiser&#39;</span><span class="p">,</span> <span class="s1">&#39;quadric&#39;</span><span class="p">,</span>
           <span class="s1">&#39;catrom&#39;</span><span class="p">,</span> <span class="s1">&#39;gaussian&#39;</span><span class="p">,</span> <span class="s1">&#39;bessel&#39;</span><span class="p">,</span> <span class="s1">&#39;mitchell&#39;</span><span class="p">,</span> <span class="s1">&#39;sinc&#39;</span><span class="p">,</span> <span class="s1">&#39;lanczos&#39;</span><span class="p">]</span>


<span class="n">grid</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>

<span class="n">fig</span><span class="p">,</span> <span class="n">axs</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">nrows</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">ncols</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span>
                        <span class="n">subplot_kw</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;xticks&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;yticks&#39;</span><span class="p">:</span> <span class="p">[]})</span>

<span class="k">for</span> <span class="n">ax</span><span class="p">,</span> <span class="n">interp_method</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">axs</span><span class="o">.</span><span class="n">flat</span><span class="p">,</span> <span class="n">methods</span><span class="p">):</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">grid</span><span class="p">,</span> <span class="n">interpolation</span><span class="o">=</span><span class="n">interp_method</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">&#39;viridis&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">interp_method</span><span class="p">))</span>

<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_29_0.png" src="../_images/index_29_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
</div>
</div>
<div class="section" id="object-container">
<h2>三、对象容器 - Object container<a class="headerlink" href="#object-container" title="永久链接至标题">¶</a></h2>
<p>容器会包含一些<code class="docutils literal notranslate"><span class="pre">primitives</span></code>，并且容器还有它自身的属性。<br />
比如<code class="docutils literal notranslate"><span class="pre">Axes</span> <span class="pre">Artist</span></code>，它是一种容器，它包含了很多<code class="docutils literal notranslate"><span class="pre">primitives</span></code>，比如<code class="docutils literal notranslate"><span class="pre">Line2D</span></code>，<code class="docutils literal notranslate"><span class="pre">Text</span></code>；同时，它也有自身的属性，比如<code class="docutils literal notranslate"><span class="pre">xscal</span></code>，用来控制X轴是<code class="docutils literal notranslate"><span class="pre">linear</span></code>还是<code class="docutils literal notranslate"><span class="pre">log</span></code>的。</p>
<div class="section" id="figure">
<h3>1. Figure容器<a class="headerlink" href="#figure" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">matplotlib.figure.Figure</span></code>是<code class="docutils literal notranslate"><span class="pre">Artist</span></code>最顶层的<code class="docutils literal notranslate"><span class="pre">container</span></code>对象容器，它包含了图表中的所有元素。一张图表的背景就是在<code class="docutils literal notranslate"><span class="pre">Figure.patch</span></code>的一个矩形<code class="docutils literal notranslate"><span class="pre">Rectangle</span></code>。<br />
当我们向图表添加<code class="docutils literal notranslate"><span class="pre">Figure.add_subplot()</span></code>或者<code class="docutils literal notranslate"><span class="pre">Figure.add_axes()</span></code>元素时，这些都会被添加到<code class="docutils literal notranslate"><span class="pre">Figure.axes</span></code>列表中。</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span> <span class="c1"># 作一幅2*1的图，选择第1个子图</span>
<span class="n">ax2</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span> <span class="c1"># 位置参数，四个数分别代表了(left,bottom,width,height)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">ax1</span><span class="p">)</span> 
<span class="nb">print</span><span class="p">(</span><span class="n">fig</span><span class="o">.</span><span class="n">axes</span><span class="p">)</span> <span class="c1"># fig.axes 中包含了subplot和axes两个实例, 刚刚添加的</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>AxesSubplot(0.125,0.536818;0.775x0.343182)
[&lt;AxesSubplot:&gt;, &lt;Axes:&gt;]
</pre></div>
</div>
<img alt="../_images/index_31_1.png" src="../_images/index_31_1.png" />
</div>
</div>
<p>​</p>
<p>由于<code class="docutils literal notranslate"><span class="pre">Figure</span></code>维持了<code class="docutils literal notranslate"><span class="pre">current</span> <span class="pre">axes</span></code>，因此你不应该手动的从<code class="docutils literal notranslate"><span class="pre">Figure.axes</span></code>列表中添加删除元素，而是要通过<code class="docutils literal notranslate"><span class="pre">Figure.add_subplot()</span></code>、<code class="docutils literal notranslate"><span class="pre">Figure.add_axes()</span></code>来添加元素，通过<code class="docutils literal notranslate"><span class="pre">Figure.delaxes()</span></code>来删除元素。但是你可以迭代或者访问<code class="docutils literal notranslate"><span class="pre">Figure.axes</span></code>中的<code class="docutils literal notranslate"><span class="pre">Axes</span></code>，然后修改这个<code class="docutils literal notranslate"><span class="pre">Axes</span></code>的属性。</p>
<p>比如下面的遍历axes里的内容，并且添加网格线：</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span>

<span class="k">for</span> <span class="n">ax</span> <span class="ow">in</span> <span class="n">fig</span><span class="o">.</span><span class="n">axes</span><span class="p">:</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_33_0.png" src="../_images/index_33_0.png" />
</div>
</div>
<p>​</p>
<p>​</p>
<p><code class="docutils literal notranslate"><span class="pre">Figure</span></code>也有它自己的<code class="docutils literal notranslate"><span class="pre">text、line、patch、image</span></code>。你可以直接通过<code class="docutils literal notranslate"><span class="pre">add</span> <span class="pre">primitive</span></code>语句直接添加。但是注意<code class="docutils literal notranslate"><span class="pre">Figure</span></code>默认的坐标系是以像素为单位，你可能需要转换成figure坐标系：(0,0)表示左下点，(1,1)表示右上点。</p>
<p><strong>Figure容器的常见属性：</strong><br />
<code class="docutils literal notranslate"><span class="pre">Figure.patch</span></code>属性：Figure的背景矩形<br />
<code class="docutils literal notranslate"><span class="pre">Figure.axes</span></code>属性：一个Axes实例的列表（包括Subplot)<br />
<code class="docutils literal notranslate"><span class="pre">Figure.images</span></code>属性：一个FigureImages patch列表<br />
<code class="docutils literal notranslate"><span class="pre">Figure.lines</span></code>属性：一个Line2D实例的列表（很少使用）<br />
<code class="docutils literal notranslate"><span class="pre">Figure.legends</span></code>属性：一个Figure Legend实例列表（不同于Axes.legends)<br />
<code class="docutils literal notranslate"><span class="pre">Figure.texts</span></code>属性：一个Figure Text实例列表</p>
</div>
<div class="section" id="axes">
<h3>2. Axes容器<a class="headerlink" href="#axes" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">matplotlib.axes.Axes</span></code>是matplotlib的核心。大量的用于绘图的<code class="docutils literal notranslate"><span class="pre">Artist</span></code>存放在它内部，并且它有许多辅助方法来创建和添加<code class="docutils literal notranslate"><span class="pre">Artist</span></code>给它自己，而且它也有许多赋值方法来访问和修改这些<code class="docutils literal notranslate"><span class="pre">Artist</span></code>。</p>
<p>和<code class="docutils literal notranslate"><span class="pre">Figure</span></code>容器类似，<code class="docutils literal notranslate"><span class="pre">Axes</span></code>包含了一个patch属性，对于笛卡尔坐标系而言，它是一个<code class="docutils literal notranslate"><span class="pre">Rectangle</span></code>；对于极坐标而言，它是一个<code class="docutils literal notranslate"><span class="pre">Circle</span></code>。这个patch属性决定了绘图区域的形状、背景和边框。</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
<span class="n">rect</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">patch</span>  <span class="c1"># axes的patch是一个Rectangle实例</span>
<span class="n">rect</span><span class="o">.</span><span class="n">set_facecolor</span><span class="p">(</span><span class="s1">&#39;green&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_35_0.png" src="../_images/index_35_0.png" />
</div>
</div>
<p>​</p>
<p><code class="docutils literal notranslate"><span class="pre">Axes</span></code>有许多方法用于绘图，如<code class="docutils literal notranslate"><span class="pre">.plot()、.text()、.hist()、.imshow()</span></code>等方法用于创建大多数常见的<code class="docutils literal notranslate"><span class="pre">primitive</span></code>(如<code class="docutils literal notranslate"><span class="pre">Line2D，Rectangle，Text，Image</span></code>等等）。在<code class="docutils literal notranslate"><span class="pre">primitives</span></code>中已经涉及，不再赘述。</p>
<p>Subplot就是一个特殊的Axes，其实例是位于网格中某个区域的Subplot实例。其实你也可以在任意区域创建Axes，通过Figure.add_axes([left,bottom,width,height])来创建一个任意区域的Axes，其中left,bottom,width,height都是[0—1]之间的浮点数，他们代表了相对于Figure的坐标。</p>
<p>你不应该直接通过<code class="docutils literal notranslate"><span class="pre">Axes.lines</span></code>和<code class="docutils literal notranslate"><span class="pre">Axes.patches</span></code>列表来添加图表。因为当创建或添加一个对象到图表中时，<code class="docutils literal notranslate"><span class="pre">Axes</span></code>会做许多自动化的工作:<br />
它会设置Artist中figure和axes的属性，同时默认Axes的转换；<br />
它也会检视Artist中的数据，来更新数据结构，这样数据范围和呈现方式可以根据作图范围自动调整。</p>
<p>你也可以使用Axes的辅助方法<code class="docutils literal notranslate"><span class="pre">.add_line()</span></code>和<code class="docutils literal notranslate"><span class="pre">.add_patch()</span></code>方法来直接添加。</p>
<p>另外Axes还包含两个最重要的Artist container：</p>
<p><code class="docutils literal notranslate"><span class="pre">ax.xaxis</span></code>：XAxis对象的实例，用于处理x轴tick以及label的绘制<br />
<code class="docutils literal notranslate"><span class="pre">ax.yaxis</span></code>：YAxis对象的实例，用于处理y轴tick以及label的绘制<br />
会在下面章节详细说明。</p>
<p><strong>Axes容器</strong>的常见属性有：<br />
<code class="docutils literal notranslate"><span class="pre">artists</span></code>:    Artist实例列表<br />
<code class="docutils literal notranslate"><span class="pre">patch</span></code>:     Axes所在的矩形实例<br />
<code class="docutils literal notranslate"><span class="pre">collections</span></code>: Collection实例<br />
<code class="docutils literal notranslate"><span class="pre">images</span></code>:    Axes图像<br />
<code class="docutils literal notranslate"><span class="pre">legends</span></code>:	  Legend 实例<br />
<code class="docutils literal notranslate"><span class="pre">lines</span></code>:	  Line2D 实例<br />
<code class="docutils literal notranslate"><span class="pre">patches</span></code>:	  Patch 实例<br />
<code class="docutils literal notranslate"><span class="pre">texts</span></code>:	  Text 实例<br />
<code class="docutils literal notranslate"><span class="pre">xaxis</span></code>:	  matplotlib.axis.XAxis 实例<br />
<code class="docutils literal notranslate"><span class="pre">yaxis</span></code>:	  matplotlib.axis.YAxis 实例</p>
</div>
<div class="section" id="axis">
<h3>3. Axis容器<a class="headerlink" href="#axis" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">matplotlib.axis.Axis</span></code>实例处理<code class="docutils literal notranslate"><span class="pre">tick</span> <span class="pre">line</span></code>、<code class="docutils literal notranslate"><span class="pre">grid</span> <span class="pre">line</span></code>、<code class="docutils literal notranslate"><span class="pre">tick</span> <span class="pre">label</span></code>以及<code class="docutils literal notranslate"><span class="pre">axis</span> <span class="pre">label</span></code>的绘制，它包括坐标轴上的刻度线、刻度<code class="docutils literal notranslate"><span class="pre">label</span></code>、坐标网格、坐标轴标题。通常你可以独立的配置y轴的左边刻度以及右边的刻度，也可以独立地配置x轴的上边刻度以及下边的刻度。</p>
<p>刻度包括主刻度和次刻度，它们都是Tick刻度对象。</p>
<p><code class="docutils literal notranslate"><span class="pre">Axis</span></code>也存储了用于自适应，平移以及缩放的<code class="docutils literal notranslate"><span class="pre">data_interval</span></code>和<code class="docutils literal notranslate"><span class="pre">view_interval</span></code>。它还有Locator实例和Formatter实例用于控制刻度线的位置以及刻度label。</p>
<p>每个Axis都有一个<code class="docutils literal notranslate"><span class="pre">label</span></code>属性，也有主刻度列表和次刻度列表。这些<code class="docutils literal notranslate"><span class="pre">ticks</span></code>是<code class="docutils literal notranslate"><span class="pre">axis.XTick</span></code>和<code class="docutils literal notranslate"><span class="pre">axis.YTick</span></code>实例，它们包含着<code class="docutils literal notranslate"><span class="pre">line</span> <span class="pre">primitive</span></code>以及<code class="docutils literal notranslate"><span class="pre">text</span> <span class="pre">primitive</span></code>用来渲染刻度线以及刻度文本。</p>
<p>刻度是动态创建的，只有在需要创建的时候才创建（比如缩放的时候）。Axis也提供了一些辅助方法来获取刻度文本、刻度线位置等等：<br />
常见的如下：</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># 不用print，直接显示结果</span>
<span class="kn">from</span> <span class="nn">IPython.core.interactiveshell</span> <span class="kn">import</span> <span class="n">InteractiveShell</span>
<span class="n">InteractiveShell</span><span class="o">.</span><span class="n">ast_node_interactivity</span> <span class="o">=</span> <span class="s2">&quot;all&quot;</span>

<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span>

<span class="n">axis</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span> <span class="c1"># axis为X轴对象</span>
<span class="n">axis</span><span class="o">.</span><span class="n">get_ticklocs</span><span class="p">()</span>     <span class="c1"># 获取刻度线位置</span>
<span class="n">axis</span><span class="o">.</span><span class="n">get_ticklabels</span><span class="p">()</span>   <span class="c1"># 获取刻度label列表(一个Text实例的列表）。 可以通过minor=True|False关键字参数控制输出minor还是major的tick label。</span>
<span class="n">axis</span><span class="o">.</span><span class="n">get_ticklines</span><span class="p">()</span>    <span class="c1"># 获取刻度线列表(一个Line2D实例的列表）。 可以通过minor=True|False关键字参数控制输出minor还是major的tick line。</span>
<span class="n">axis</span><span class="o">.</span><span class="n">get_data_interval</span><span class="p">()</span><span class="c1"># 获取轴刻度间隔</span>
<span class="n">axis</span><span class="o">.</span><span class="n">get_view_interval</span><span class="p">()</span><span class="c1"># 获取轴视角（位置）的间隔</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>array([-0.2,  4.2])
</pre></div>
</div>
<img alt="../_images/index_37_1.png" src="../_images/index_37_1.png" />
</div>
</div>
<p>​</p>
<p>下面的例子展示了如何调整一些轴和刻度的属性(忽略美观度，仅作调整参考)：</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span> <span class="c1"># 创建一个新图表</span>
<span class="n">rect</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">patch</span>   <span class="c1"># 矩形实例并将其设为黄色</span>
<span class="n">rect</span><span class="o">.</span><span class="n">set_facecolor</span><span class="p">(</span><span class="s1">&#39;lightgoldenrodyellow&#39;</span><span class="p">)</span>

<span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">])</span> <span class="c1"># 创一个axes对象，从(0.1,0.3)的位置开始，宽和高都为0.4，</span>
<span class="n">rect</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">patch</span>   <span class="c1"># ax1的矩形设为灰色</span>
<span class="n">rect</span><span class="o">.</span><span class="n">set_facecolor</span><span class="p">(</span><span class="s1">&#39;lightslategray&#39;</span><span class="p">)</span>


<span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">ax1</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">get_ticklabels</span><span class="p">():</span> 
    <span class="c1"># 调用x轴刻度标签实例，是一个text实例</span>
    <span class="n">label</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="s1">&#39;red&#39;</span><span class="p">)</span> <span class="c1"># 颜色</span>
    <span class="n">label</span><span class="o">.</span><span class="n">set_rotation</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span> <span class="c1"># 旋转角度</span>
    <span class="n">label</span><span class="o">.</span><span class="n">set_fontsize</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span> <span class="c1"># 字体大小</span>

<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">ax1</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">get_ticklines</span><span class="p">():</span>
    <span class="c1"># 调用y轴刻度线条实例, 是一个Line2D实例</span>
    <span class="n">line</span><span class="o">.</span><span class="n">set_markeredgecolor</span><span class="p">(</span><span class="s1">&#39;green&#39;</span><span class="p">)</span>    <span class="c1"># 颜色</span>
    <span class="n">line</span><span class="o">.</span><span class="n">set_markersize</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span>    <span class="c1"># marker大小</span>
    <span class="n">line</span><span class="o">.</span><span class="n">set_markeredgewidth</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="c1"># marker粗细</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_39_0.png" src="../_images/index_39_0.png" />
</div>
</div>
<p>​</p>
</div>
<div class="section" id="tick">
<h3>4. Tick容器<a class="headerlink" href="#tick" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">matplotlib.axis.Tick</span></code>是从<code class="docutils literal notranslate"><span class="pre">Figure</span></code>到<code class="docutils literal notranslate"><span class="pre">Axes</span></code>到<code class="docutils literal notranslate"><span class="pre">Axis</span></code>到<code class="docutils literal notranslate"><span class="pre">Tick</span></code>中最末端的容器对象。<br />
<code class="docutils literal notranslate"><span class="pre">Tick</span></code>包含了<code class="docutils literal notranslate"><span class="pre">tick</span></code>、<code class="docutils literal notranslate"><span class="pre">grid</span> <span class="pre">line</span></code>实例以及对应的<code class="docutils literal notranslate"><span class="pre">label</span></code>。</p>
<p>所有的这些都可以通过<code class="docutils literal notranslate"><span class="pre">Tick</span></code>的属性获取，常见的<code class="docutils literal notranslate"><span class="pre">tick</span></code>属性有<br />
<code class="docutils literal notranslate"><span class="pre">Tick.tick1line</span></code>：Line2D实例<br />
<code class="docutils literal notranslate"><span class="pre">Tick.tick2line</span></code>：Line2D实例<br />
<code class="docutils literal notranslate"><span class="pre">Tick.gridline</span></code>：Line2D实例<br />
<code class="docutils literal notranslate"><span class="pre">Tick.label1</span></code>：Text实例<br />
<code class="docutils literal notranslate"><span class="pre">Tick.label2</span></code>：Text实例</p>
<p>y轴分为左右两个，因此tick1对应左侧的轴；tick2对应右侧的轴。<br />
x轴分为上下两个，因此tick1对应下侧的轴；tick2对应上侧的轴。</p>
<p>下面的例子展示了，如何将Y轴右边轴设为主轴，并将标签设置为美元符号且为绿色：</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span>

<span class="c1"># 设置ticker的显示格式</span>
<span class="n">formatter</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">ticker</span><span class="o">.</span><span class="n">FormatStrFormatter</span><span class="p">(</span><span class="s1">&#39;$</span><span class="si">%1.2f</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">set_major_formatter</span><span class="p">(</span><span class="n">formatter</span><span class="p">)</span>

<span class="c1"># 设置ticker的参数，右侧为主轴，颜色为绿色</span>
<span class="n">ax</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">set_tick_params</span><span class="p">(</span><span class="n">which</span><span class="o">=</span><span class="s1">&#39;major&#39;</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="s1">&#39;green&#39;</span><span class="p">,</span>
                         <span class="n">labelleft</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">labelright</span><span class="o">=</span><span class="kc">True</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/index_41_0.png" src="../_images/index_41_0.png" />
</div>
</div>
<p>​</p>
</div>
</div>
<div class="section" id="id3">
<h2>思考题<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h2>
<ul class="simple">
<li><p>primitives 和 container的区别和联系是什么，分别用于控制可视化图表中的哪些要素</p></li>
<li><p>使用提供的drug数据集，对第一列yyyy和第二列state分组求和，画出下面折线图。PA加粗标黄，其他为灰色。<br />
图标题和横纵坐标轴标题，以及线的文本暂不做要求。</p></li>
</ul>
<p><img alt="" src="https://img-blog.csdnimg.cn/20210523162430365.png" /></p>
<ul class="simple">
<li><p>分别用一组长方形柱和填充面积的方式模仿画出下图，函数 y = -1 * (x - 2) * (x - 8) +10 在区间[2,9]的积分面积<br />
<img alt="" src="https://img-blog.csdnimg.cn/20201126105910781.png" /><br />
<img alt="" src="https://img-blog.csdnimg.cn/20201126105910780.png" /></p></li>
</ul>
</div>
<div class="section" id="id4">
<h2>参考资料<a class="headerlink" href="#id4" title="永久链接至标题">¶</a></h2>
<p><a class="reference external" href="https://zhuanlan.zhihu.com/p/32693665">1. matplotlib设计的基本逻辑</a><br />
<a class="reference external" href="https://www.bookstack.cn/read/huaxiaozhuan-ai/spilt.2.333f5abdbabf383d.md">2. AI算法工程师手册</a></p>
</div>
</div>


              </div>
              
        
        <div class='prev-next-bottom'>
            
    <a class='left-prev' id="prev-link" href="../%E7%AC%AC%E4%B8%80%E5%9B%9E%EF%BC%9AMatplotlib%E5%88%9D%E7%9B%B8%E8%AF%86/index.html" title="previous page">第一回：Matplotlib初相识</a>
    <a class='right-next' id="next-link" href="../%E7%AC%AC%E4%B8%89%E5%9B%9E%EF%BC%9A%E5%B8%83%E5%B1%80%E6%A0%BC%E5%BC%8F%E5%AE%9A%E6%96%B9%E5%9C%86/index.html" title="next page">第三回：布局格式定方圆</a>

        </div>
        
        </div>
    </div>
    <footer class="footer mt-5 mt-md-0">
    <div class="container">
      <p>
        
          By Datawhale数据可视化开源小组<br/>
        
            &copy; Copyright © Copyright 2021.<br/>
      </p>
    </div>
  </footer>
</main>


      </div>
    </div>
  
  <script src="../_static/js/index.1c5a1a01449ed65a7b51.js"></script>

  
  </body>
</html>